//
//  ZheXianTableViewCell.m
//  DBAChain
//
//  Created by Evan on 2018/9/6.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "ZheXianTableViewCell.h"
#import "CommonData.h"

@implementation ZheXianTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath
{
    NSString *Service = [NSString stringWithFormat:@"ZheXianTableViewCell_%ld_%ld",(long)indexPath.section,(long)indexPath.row];
    ZheXianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Service];
    if (cell == nil) {
        [tableView registerClass:[ZheXianTableViewCell class] forCellReuseIdentifier:Service];
        cell = [tableView dequeueReusableCellWithIdentifier:Service];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor clearColor];
    }
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(AAChartView*)aaChartView{
    if (!_aaChartView) {
        _aaChartView = [[AAChartView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth , 300)];
        _aaChartView.backgroundColor = [UIColor clearColor];
        _aaChartView.contentHeight =300;
        _aaChartView.isClearBackgroundColor = YES;
        [self addSubview:_aaChartView];
    }
    return _aaChartView;
}

-(void)initData:(NSArray<dataTradPriceInfo*> *) orderList{
//    if([orderList count] != 9) return;
    
    NSMutableArray *arrayPrice = [[NSMutableArray alloc]init];
    NSMutableArray *arrayDate = [[NSMutableArray alloc]init];

//    for (NSInteger i = ([orderList count] -1); i >= 0; i--) {

//    for (NSInteger i = 0; i < [orderList count]; i++) {
//
//        dataTradPriceInfo *mm = [dataTradPriceInfo mj_objectWithKeyValues:[orderList objectAtIndex:i]];
//        NSString* dateStr = mm.createTime;
//
//        NSDateFormatter* formater = [[NSDateFormatter alloc] init];
//        [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//        formater.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
//        NSDate* date = [formater dateFromString:dateStr];
//        [formater setDateFormat:@"MM-dd"];
//        NSString *str = [formater stringFromDate:date];
//        [arrayDate addObject:str];
//        [arrayPrice addObject:@(mm.price)];
//    }
    
    
     AAChartModel *chartModel= AAObject(AAChartModel)
    .chartTypeSet(AAChartTypeSpline)//设置图表的类型(这里以设置的为柱状图为例)
    .titleSet(@"GTE每日CNY价格")//设置图表标题
    .subtitleSet(@"价格")//设置图表副标题
    .categoriesSet(arrayDate)//@[@"Java",@"Swift",@"Python",@"Ruby", @"PHP",@"Go",@"C",@"C#",@"C++"])//设置图表横轴的内容
    .yAxisTitleSet(@"CNY")//设置图表 y 轴的单位
    .seriesSet(@[
                 AAObject(AASeriesElement)
                 .nameSet(@"GTE")
                 .dataSet(arrayPrice),//@[@45,@56,@34,@43,@65,@56,@47,@28,@49]),
//                 AAObject(AASeriesElement)
//                 .nameSet(@"GTE")
//                 .dataSet(@[@11,@12,@13,@14,@15,@16,@17,@18,@19]),
//                 AAObject(AASeriesElement)
//                 .nameSet(@"2019")
//                 .dataSet(@[@31,@22,@33,@54,@35,@36,@27,@38,@39]),
//                 AAObject(AASeriesElement)
//                 .nameSet(@"2020")
//                 .dataSet(@[@21,@22,@53,@24,@65,@26,@37,@28,@49]),
                 ])
    ;
   
    
    /*图表视图对象调用图表模型对象,绘制最终图形*/
    [self.aaChartView aa_drawChartWithChartModel:chartModel];
    [self.aaChartView aa_refreshChartWithChartModel:chartModel];
}




@end
